package com.codeoss.framework.data.metadata;

import java.util.Collection;

public class Restrictions {
   public Restrictions(){
	   
   }
   
   public static Expression like(String name,String value){
	   Expression expression=new Expression();
	   expression.setName(name);
	   expression.setValue1(value);
	   expression.setOperation("like");
	   return expression;
   }
   
   public static Expression likeLeft(String name,String value){
	   Expression expression=new Expression();
	   expression.setName(name);
	   expression.setValue1(value);
	   expression.setOperation("likeLeft");
	   return expression;
   }
   
   public static Expression likeRight(String name,String value){
	   Expression expression=new Expression();
	   expression.setName(name);
	   expression.setValue1(value);
	   expression.setOperation("likeRight");
	   return expression;
   }
   
   public static Expression between(String name,Object value1,Object value2){
	   Expression expression=new Expression();
	   expression.setName(name);
	   expression.setValue1(value1);
	   expression.setValue2(value2);
	   expression.setOperation("between");
	   return expression;
   }
   
   /**
    * 等于
    * @param name
    * @param value
    * @return
    */
   public static Expression eq(String name,Object value){
	   Expression expression=new Expression();
	   expression.setName(name);
	   expression.setValue1(value);
	   expression.setOperation("=");
	   return expression;
   }
   
   /**
    * 不等于
    * @param name
    * @param value
    * @return
    */
   public static Expression ne(String name,Object value){
	   Expression expression=new Expression();
	   expression.setName(name);
	   expression.setValue1(value);
	   expression.setOperation("<>");
	   return expression;
   }
   
   /**
    * 大于
    * @param name
    * @param value
    * @return
    */
   public static Expression gt(String name,Object value){
	   Expression expression=new Expression();
	   expression.setName(name);
	   expression.setValue1(value);
	   expression.setOperation(">");
	   return expression;
   }
   
   /**
    * 小于
    * @param name
    * @param value
    * @return
    */
   public static Expression lt(String name,Object value){
	   Expression expression=new Expression();
	   expression.setName(name);
	   expression.setValue1(value);
	   expression.setOperation("<");
	   return expression;
   }
   
   /**
    * 大于等于
    * @param name
    * @param value
    * @return
    */
   public static Expression ge(String name,Object value){
	   Expression expression=new Expression();
	   expression.setName(name);
	   expression.setValue1(value);
	   expression.setOperation(">=");
	   return expression;
   }
   
   /**
    * 小于等于
    * @param name
    * @param value
    * @return
    */
   public static Expression le(String name,Object value){
	   Expression expression=new Expression();
	   expression.setName(name);
	   expression.setValue1(value);
	   expression.setOperation("<=");
	   return expression;
   }
   
   public static Expression in(String name,Object[] values){
	   Expression expression=new Expression();
	   expression.setName(name);
	   expression.setValue1(values);
	   expression.setOperation("in");
	   return expression;
   }
   
   public static Expression in(String name,Collection<Object> values){
	   Expression expression=new Expression();
	   expression.setName(name);
	   expression.setValue1(values);
	   expression.setOperation("in");
	   return expression;
   }
   
   public static Expression notin(String name,Collection<Object> values){
	   Expression expression=new Expression();
	   expression.setName(name);
	   expression.setValue1(values);
	   expression.setOperation("notin");
	   return expression;
   }
   
   public static Expression isNull(String name){
	   Expression expression=new Expression();
	   expression.setName(name);
	   expression.setOperation("isnull");
	   return expression;
   }
   
   public static Expression isNotNull(String name){
	   Expression expression=new Expression();
	   expression.setOperation("isnotnull");
	   return expression;
   }
   
   public static Expression or(Expression... expressions){
	   Expression expression=new Expression();
	   expression.setOperation("or");
	   for(int i=0;i<expressions.length;i++){
		   expression.add(expressions[i]);
	   }
	   return expression;
   }
   
   public static Expression and(Expression... expressions){
	   Expression expression=new Expression();
	   expression.setOperation("and");
	   for(int i=0;i<expressions.length;i++){
		   expression.add(expressions[i]);
	   }
	   return expression;
   }
   
   public static Expression not(Expression epress){
	   Expression expression=new Expression();
	   expression.setOperation("not");
	   expression.add(epress);
	   return expression;
   }
   
   public static Expression sql(String sql){
	   Expression expression=new Expression();
	   expression.setSQL(sql);
	   return expression;
   }
}
